package com.fanshilz.flower2025.apps.admin.bid.controller;

import com.fanshilz.flower2025.apps.admin.bid.req.ProjectBidTableReq;
import com.fanshilz.flower2025.apps.admin.bid.resp.ProjectBidTableDetailResp;
import com.fanshilz.flower2025.business.flower.projectBid.service.IProjectBidService;
import com.fanshilz.flower2025.framework.resp.Resp;
import com.fanshilz.flower2025.framework.resp.TableResp;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/bid")
public class BidController {

    @Resource
    private IProjectBidService projectBidService;

    @PostMapping("/table")
    public Resp<TableResp<ProjectBidTableDetailResp>> table(@RequestBody @Valid ProjectBidTableReq req) {
        QueryWrapper qw = QueryWrapper.create();
        Page<ProjectBidTableDetailResp> page = projectBidService.getMapper()
                .paginateWithRelationsAs(Page.of(req.getCurrent(), req.getPageSize(), req.getTotal()), qw, ProjectBidTableDetailResp.class);
        return Resp.success(new TableResp<>(page.getRecords(), page.getTotalRow()));
    }

}
